package servlet;

import dao.CartDAO;
import entity.Cart;
import entity.PageBean;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "cartListAll",value = "/cart/list")
public class CartListAllServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int pageNum = 1;
        int pageSize = 10;
        //2. 将pageNum pageSize === skip 和limit
        int skip = (pageNum-1)*pageSize;
        int limit = pageSize;
        CartDAO cartDAO = new CartDAO();
        List<Cart> list =cartDAO.findPage(skip,limit);
        long total = cartDAO.getCount();
        PageBean<Cart> page=new PageBean<>();
        page.setPageNum(pageNum);
        page.setPageSize(pageSize);
        page.setList(list);
        page.setTotal(total);
        page.setPageTotal(total,pageSize);
        request.setAttribute("page",page);
        request.getRequestDispatcher("/cart/List.jsp").forward(request,response);
    }
}
